<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .da {
            width: 800px;
            height: 500px;
            border-radius: 5px;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            padding-top: 10px;
        }

        textarea {
            width: 800px;
            height: 80px;
        }

        input {
            height: 20px;
            float: left;
        }

        .tx {
            width: 20px;
            height: 20px;
            margin-left: 3px;
            
        }

        .zong {
            width: 800px;
            height: 50px;
            background-color: #a7b7c9;
            margin-top: 30px;
        }

        .xiao {
            width: 100px;
            height: 40px;
            background-color: white;
            margin-top: 10px;
            margin-left: 10px;
            float: left;
        }

        .zt {
            margin-left: 15px;
            margin-top: 15px;
        }

        .img {
            width: 40px;
            height: 40px;
            margin-top: 15px;
            margin-left: 15px;
            float: left;
        }

        .ss {

            margin-left: 10px;
        }

        .sj {
            margin-left: 10px;
        }

        .aa {
            margin-top: 10px;
            float: left;
        }

        .sc {
            margin-left: 100px;
            font-size: 20px;
            border: 4px solid blue;
            color: red;
        }
        button{
            width: 100px;
            background-color: aqua;
            float: right;
        }
        span{
            display: block;
        }
    </style>
</head>

<body>
    <div class="da">
        来，说说你在做什么，想什么<br>
        <input type="text"><img class="tx" src="./古月方源.jpeg" value="./古月方源.jpeg"><img class="tx" src="./1.jpg" value="./1.jpg"><img
            class="tx" src="./2.jpg" value="./2.jpg"><img class="tx" src="./3.jpg" value="./3.jpg"><img class="tx" src="./4.jpg"
            value="./4.jpg"><img class="tx" src="./5.jpg" value="./5.jpg">
        <p><textarea oninput="f1()" maxlength="20"></textarea> 还有<samp class="num">20</samp>个字<button class="button">发布</button></p>
        <div class="zong">
            <div class="xiao">
                <p class="zt">我也说说</p>
            </div>
        </div>
        <div class="aa">
            <!-- <img  class="img" src="./古月方源.jpeg">
            <span class="ss">111说：大家好 </span><button class="sc">删除</button><br><span class="sj">时间</span> -->
        </div>
    </div>
</body>

</html>
<script>
    var txarr = document.querySelectorAll('img')
    var div = document.querySelector('.aa')
    var button = document.querySelector('.button')
    var input = document.querySelector('input')
    var text = document.querySelector('textarea')
    var span = document.querySelector('span')
    var num = document.querySelector('.num')
   
    for (i = 0; i < txarr.length ; i++) {
        txarr[i].onclick=function () {
            lj=this.src;
            for (i = 0; i < txarr.length; i++) {
                txarr[i].style.border=''
            }
            this.style.border='1px solid red'
        }
    }
    button.onclick=function(){
        var date=new Date();
        var yue=date.getMonth()+1;
        var ri=date.getDate();
        var time=date.toLocaleString().split(" ")[1]
        var p=document.createElement("span")
        if(text.value.trim()==''){
            alert("内容为空，不能添加")
            return
        }
        p.innerHTML=`
        <img  class="img" src="${lj}">
        <span class="ss">${input.value}说：${text.value} </span>
        <span class="sj">${yue}月${ri}日${time}</span>
        <button class="sc" onclick="f(this)">删除</button>
        `;
        div.insertBefore(p,div.children[0])
    }
    function f(shanchu){
        div.removeChild(shanchu.parentNode)
    }
    function f1(){
        num.innerHTML=20-text.value.length
    }
</script>